# 与题中的要求不符
class Solution:
    def relativeSortArray(self, arr1: List[int], arr2: List[int]) -> List[int]:
        for j in range(len(arr2)):
            for i in range(j, len(arr1)):
                if arr2[j] == arr1[i]:
                    tmp = arr1[i]
                    arr1[i] = arr1[j]
                    arr1[j] = tmp
                    break
        arr1[len(arr2):].sort()
        return arr1

# 更好的方法
class Solution:
    def relativeSortArray(self, arr1: List[int], arr2: List[int]) -> List[int]:
        def mycmp(x: int) -> (int, int):
            return (0, rank[x]) if x in rank else (1, x)

        rank = {x: i for i, x in enumerate(arr2)}
        arr1.sort(key=mycmp)
        return arr1


# 作者：LeetCode - Solution
# 链接：https: // leetcode - cn.com / problems / relative - sort - array / solution / shu - zu - de - xiang - dui - pai - xu - by - leetcode - solution /
# 来源：力扣（LeetCode）
# 著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。